#!/usr/bin/env python
# -*-coding:utf-8 -*-
import json
import base64
import uuid


class String(object):
    def to_string(self):
        return json.dumps(self.__dict__)

    def to_json(self):
        return self.__dict__

    def from_json(self, s):
        for key in self.__dict__.keys():
            setattr(self, key, s.get(key))


class SpiderConfig(String):
    def __init__(self):
        self.groupId = ''
        self.spiderId = ''
        self.state = 1
        self.spiderName = ''
        self.website = ''
        self.domain = ''
        self.spiderQueue = ''
        self.reaperQueue = ''
        self.siteName = ''
        self.threadNum = 1
        self.startUrl = ''


class Page(String):
    def __init__(self):
        self.status = False
        self.url = ''
        self.result = {}
        self.data = []
        self.domain = ''
        self.website = ''
        self.urlList = []
        self.isSkip = False
        self.messageId = ''
        self.taskId = ''


class Message(String):
    def __init__(self, task_id, message, delay=0):
        base64_message = base64.b64encode(message.encode("utf-8"))
        self.message = str(base64_message, 'utf-8')
        self.queueName = ''
        self.priority = 8
        self.delaySeconds = delay
        self.taskId = task_id if task_id else str(uuid.uuid1()).replace('-', '')
